import screen from '@ohos.screen';
import { initInfo } from "./log";

let log = initInfo('utils');

/*
 * 获取数据类型
 * return 'null'|'undefined'|'boolean'|'number'|'string'|'object'|'array'|'set'|'map'|'symbol'|'date'|'function'
 * */
export function objType(obj:any): string {
    return Object.prototype.toString.call(obj).replace(/\[object /, '').replace(/\]/, '').toLowerCase();
}

// 获取横竖屏
export async function getScreenOrientation() {
    let screenArr = await screen.getAllScreens();
    let orientation = screenArr[0].orientation;
    log('getScreenOrientation change orientation:' + orientation);
    return orientation;
}

export function isVideoFile(name: string) {
    if (name.includes('.')) {
        let type = name.split('.').pop().toLocaleLowerCase()
        let types = 'mp4;mpeg-ts;webm;mkv;mpeg;mov;ts;avi;f4v;flv;m4v;mpg'.toLocaleLowerCase();
        return types.includes(type);
    }
    return false;
}


export const util = { objType, getScreenOrientation, isVideoFile }